package com.cloudcreativity.blyg.sqlite.utils;

import android.content.Context;

import com.cloudcreativity.blyg.sqlite.CategoryOne;
import com.cloudcreativity.blyg.sqlite.CategoryTwo;

import java.util.List;

public class CategoryDaoUtils {
    private static final String TAG = CategoryDaoUtils.class.getSimpleName();
    private DaoManager mManager;

    public CategoryDaoUtils(Context context) {
        mManager = DaoManager.getInstance();
        mManager.init(context);
    }

    public boolean insertAllCategoryOne(List<CategoryOne> ones){
        try {
            mManager.getDaoSession().getCategoryOneDao()
                    .insertOrReplaceInTx(ones);
            return true;
        }catch (Exception e){
            return false;
        }
    }

    public boolean insertAllCategoryTwo(List<CategoryTwo> twos){
        try {
            mManager.getDaoSession().getCategoryTwoDao()
                    .insertOrReplaceInTx(twos);
            return true;
        }catch (Exception e){
            return false;
        }
    }

    public CategoryOne getCateOneById(Long id){
        return mManager.getDaoSession().getCategoryOneDao()
                .loadByRowId(id);
    }

    public CategoryTwo getCateTwoById(Long id){
        return mManager.getDaoSession().getCategoryTwoDao()
                .loadByRowId(id);
    }

    public List<CategoryOne> getAllCategories(){
        try {
            return mManager.getDaoSession().getCategoryOneDao().queryBuilder().list();
        }catch (Exception e){
            return null;
        }
    }
}
